<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 不并发的情况
        // async function f(){
        //     let time1 = new Date();
        //     let data1 = await new Promise((resolve, reject) => {
        //         setTimeout(() => {
        //             resolve('123')
        //         }, 2000);
        //     });
        //     let data2 = await new Promise((resolve, reject) => {
        //         setTimeout(() => {
        //             resolve('1234')
        //         }, 3000);
        //     });
        //     // 123 1234 用时：5002  该用时处理无法接受
        //     console.log(data1, data2, '用时：' + (new Date() - time1));
        // }

        // 并发处理异步  Promise.all  但该情况限于两个异步任务无数据关联的情况下使用
        async function f(){
            let time1 = new Date();
            let [data1, data2] = await Promise.all([
                new Promise((resolve, reject) => {
                    setTimeout(() => {
                        resolve('123')
                    }, 2000);
                }),
                new Promise((resolve, reject) => {
                    setTimeout(() => {
                        resolve('1234')
                    }, 3000)
                })    
            ]);

            // 123 1234 用时：3000
            console.log(data1, data2, '用时：' + (new Date() - time1));
        }
    </script>
</body>
</html>